/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package de.hsmannheim.pepa.patientenportal.apanwep.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import de.hsmannheim.pepa.patientenportal.apanwep.service.ClpSerializer;
import de.hsmannheim.pepa.patientenportal.apanwep.service.objectsLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Cedric Nana
 */
public class objectsClp extends BaseModelImpl<objects> implements objects {
	public objectsClp() {
	}

	@Override
	public Class<?> getModelClass() {
		return objects.class;
	}

	@Override
	public String getModelClassName() {
		return objects.class.getName();
	}

	@Override
	public long getPrimaryKey() {
		return _objectID;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setObjectID(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _objectID;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("objectID", getObjectID());
		attributes.put("objectname", getObjectname());
		attributes.put("object_ID", getObject_ID());
		attributes.put("objecttypecode", getObjecttypecode());
		attributes.put("objecttypecoderole", getObjecttypecoderole());
		attributes.put("objectidtypecode_id", getObjectidtypecode_id());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long objectID = (Long)attributes.get("objectID");

		if (objectID != null) {
			setObjectID(objectID);
		}

		String objectname = (String)attributes.get("objectname");

		if (objectname != null) {
			setObjectname(objectname);
		}

		String object_ID = (String)attributes.get("object_ID");

		if (object_ID != null) {
			setObject_ID(object_ID);
		}

		Long objecttypecode = (Long)attributes.get("objecttypecode");

		if (objecttypecode != null) {
			setObjecttypecode(objecttypecode);
		}

		Long objecttypecoderole = (Long)attributes.get("objecttypecoderole");

		if (objecttypecoderole != null) {
			setObjecttypecoderole(objecttypecoderole);
		}

		Long objectidtypecode_id = (Long)attributes.get("objectidtypecode_id");

		if (objectidtypecode_id != null) {
			setObjectidtypecode_id(objectidtypecode_id);
		}
	}

	@Override
	public long getObjectID() {
		return _objectID;
	}

	@Override
	public void setObjectID(long objectID) {
		_objectID = objectID;

		if (_objectsRemoteModel != null) {
			try {
				Class<?> clazz = _objectsRemoteModel.getClass();

				Method method = clazz.getMethod("setObjectID", long.class);

				method.invoke(_objectsRemoteModel, objectID);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getObjectname() {
		return _objectname;
	}

	@Override
	public void setObjectname(String objectname) {
		_objectname = objectname;

		if (_objectsRemoteModel != null) {
			try {
				Class<?> clazz = _objectsRemoteModel.getClass();

				Method method = clazz.getMethod("setObjectname", String.class);

				method.invoke(_objectsRemoteModel, objectname);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getObject_ID() {
		return _object_ID;
	}

	@Override
	public void setObject_ID(String object_ID) {
		_object_ID = object_ID;

		if (_objectsRemoteModel != null) {
			try {
				Class<?> clazz = _objectsRemoteModel.getClass();

				Method method = clazz.getMethod("setObject_ID", String.class);

				method.invoke(_objectsRemoteModel, object_ID);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getObjecttypecode() {
		return _objecttypecode;
	}

	@Override
	public void setObjecttypecode(long objecttypecode) {
		_objecttypecode = objecttypecode;

		if (_objectsRemoteModel != null) {
			try {
				Class<?> clazz = _objectsRemoteModel.getClass();

				Method method = clazz.getMethod("setObjecttypecode", long.class);

				method.invoke(_objectsRemoteModel, objecttypecode);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getObjecttypecoderole() {
		return _objecttypecoderole;
	}

	@Override
	public void setObjecttypecoderole(long objecttypecoderole) {
		_objecttypecoderole = objecttypecoderole;

		if (_objectsRemoteModel != null) {
			try {
				Class<?> clazz = _objectsRemoteModel.getClass();

				Method method = clazz.getMethod("setObjecttypecoderole",
						long.class);

				method.invoke(_objectsRemoteModel, objecttypecoderole);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getObjectidtypecode_id() {
		return _objectidtypecode_id;
	}

	@Override
	public void setObjectidtypecode_id(long objectidtypecode_id) {
		_objectidtypecode_id = objectidtypecode_id;

		if (_objectsRemoteModel != null) {
			try {
				Class<?> clazz = _objectsRemoteModel.getClass();

				Method method = clazz.getMethod("setObjectidtypecode_id",
						long.class);

				method.invoke(_objectsRemoteModel, objectidtypecode_id);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getobjectsRemoteModel() {
		return _objectsRemoteModel;
	}

	public void setobjectsRemoteModel(BaseModel<?> objectsRemoteModel) {
		_objectsRemoteModel = objectsRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _objectsRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_objectsRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	@Override
	public void persist() throws SystemException {
		if (this.isNew()) {
			objectsLocalServiceUtil.addobjects(this);
		}
		else {
			objectsLocalServiceUtil.updateobjects(this);
		}
	}

	@Override
	public objects toEscapedModel() {
		return (objects)ProxyUtil.newProxyInstance(objects.class.getClassLoader(),
			new Class[] { objects.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		objectsClp clone = new objectsClp();

		clone.setObjectID(getObjectID());
		clone.setObjectname(getObjectname());
		clone.setObject_ID(getObject_ID());
		clone.setObjecttypecode(getObjecttypecode());
		clone.setObjecttypecoderole(getObjecttypecoderole());
		clone.setObjectidtypecode_id(getObjectidtypecode_id());

		return clone;
	}

	@Override
	public int compareTo(objects objects) {
		long primaryKey = objects.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof objectsClp)) {
			return false;
		}

		objectsClp objects = (objectsClp)obj;

		long primaryKey = objects.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(13);

		sb.append("{objectID=");
		sb.append(getObjectID());
		sb.append(", objectname=");
		sb.append(getObjectname());
		sb.append(", object_ID=");
		sb.append(getObject_ID());
		sb.append(", objecttypecode=");
		sb.append(getObjecttypecode());
		sb.append(", objecttypecoderole=");
		sb.append(getObjecttypecoderole());
		sb.append(", objectidtypecode_id=");
		sb.append(getObjectidtypecode_id());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(22);

		sb.append("<model><model-name>");
		sb.append("de.hsmannheim.pepa.patientenportal.apanwep.model.objects");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>objectID</column-name><column-value><![CDATA[");
		sb.append(getObjectID());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>objectname</column-name><column-value><![CDATA[");
		sb.append(getObjectname());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>object_ID</column-name><column-value><![CDATA[");
		sb.append(getObject_ID());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>objecttypecode</column-name><column-value><![CDATA[");
		sb.append(getObjecttypecode());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>objecttypecoderole</column-name><column-value><![CDATA[");
		sb.append(getObjecttypecoderole());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>objectidtypecode_id</column-name><column-value><![CDATA[");
		sb.append(getObjectidtypecode_id());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _objectID;
	private String _objectname;
	private String _object_ID;
	private long _objecttypecode;
	private long _objecttypecoderole;
	private long _objectidtypecode_id;
	private BaseModel<?> _objectsRemoteModel;
}